$(function() {
	var deposit = {
		pay: function() {
			var parnt = /([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])/;
			$('[data-role="submit"]').on('click', function() {
				if(!parnt.exec($('input[name="amount"]').val())) {
					iosOverlay({
						text: '金额只能是大于0的数字',
						duration: 1000
					});
					return;
				}
				$("#payform").prop('action', './member-deposit-waiting.html?amount=' + $('input[name="amount"]').val()+ '&payment=' + $("input[type='radio']:checked").val())
				$("#payform").submit();
			})
		},
		getPrice: function() {
			$.ajax({
	            url: wsCommon.host + '/api/membersAdvance/rechargeInfo',
	            dataType: wsCommon.jsonType,
	            success: function(res) {
	                if(res.code == 1) {
	                    if(!res.result) {
	                        wsCommon.setCookie('go_back_link', window.location.href);
	                        window.location.href = './passport-login.html';
	                        return;
	                    }

	                    $('[data-role="price"]').html('¥' + res.data.currentAdvance);
	                } else {
	                    iosOverlay({
	                        text: res.reason,
	                        duration: 1000
	                    });
	                }
	            },
	            error: function(e) {
	            }
	        })
		},
		getStatus: function() {
			var code = wsCommon.getUrlParam('code');
			if(code == 0) {
				iosOverlay({
					text: '支付成功',
					duration: 1000
				});
			} else if(code == 1) {
				iosOverlay({
					text: '支付失败',
					duration: 1000
				});
			}
		},
		init: function() {
			this.pay();
			this.getPrice();
			this.getStatus();
		}
	}

	deposit.init();
})
